<?php
//!
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Default_',
			'basePath'  => dirname(__FILE__),
        ));
        return $autoloader;
    }

    protected function _initView()
    {
        $view = new Zend_View();
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->setView($view);
        $options = $this->getOption('view');
        $view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
        return $view;
    }

    protected function _initRoute()
    {
    	$recipesRoute = new Zend_Controller_Router_Route(
            'recipes/:foodType/:page',
            array(
            	'controller' => 'recipes',
                'action'     => 'index',
            	'foodType'   => 'all',
            	'page'       => '1'
            ),
            array(
            	'foodType'   => '[_a-zA-Z]+',
            	'page'       => '[\d]+'
            )
        );
        
        $ingredientsRoute = new Zend_Controller_Router_Route(
            'ingredient/:ingredient/:page',
            array(
            	'controller' => 'recipes',
                'action'     => 'ingredient',
            	'page'       => '1'
            ),
            array(
            	'page'       => '[\d]+',
            	'ingredient' => '[ a-zA-Zа-яА-ЯёЁ]+'
            )
        );
        
        $recipeRoute = new Zend_Controller_Router_Route(
            'recipe/:page',
            array(
            	'controller' => 'recipes',
                'action'     => 'recipe'
            ),
            array(
            	'page'       => '\d+'
            )
        );
        
        $adminRoute = new Zend_Controller_Router_Route(
            '2533/:action/:recipeId',
            array(
            	'controller' => 'admin',
                'action'     => 'index',
            	'recipeId'       => 0
            ),
            array(
            	'recipeId'       => '\d+'
            )
        );
        
        $ctrl=Zend_Controller_Front::getInstance();
		$router = $ctrl->getRouter();
		$router->addRoute('recipesRoute', $recipesRoute)
		       ->addRoute('recipeRoute', $recipeRoute)
		       ->addRoute('adminRoute', $adminRoute)
		       ->addRoute('ingredientsRoute', $ingredientsRoute)
		       ;
    }
    
    protected function _initDatabase()
	{
		$db = $this->getResource('db');
		Zend_Registry::set('db', $db);
	}
	
	protected function _initAcl()
	{
	    $acl = new Zend_Acl();
	    
	    $acl->addRole(new Zend_Acl_Role('Administrator'));
	    
	    $authorized = array('Administrator');
	    
	    $acl->add(new Zend_Acl_Resource('authorizationRequired'));
	    
	    $acl->allow($authorized, 'authorizationRequired', 'view');
	    
	    Zend_Registry::set('acl', $acl);
	}
}